import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;


public class gradecalc extends Applet implements ActionListener  {
        int aval, bval, cval, mark;
        boolean papass, sapass, capass, hapass, eapass, showres;
        TextField afield = new TextField("A's scored", 10);
        TextField bfield = new TextField("B's scored", 10);
        TextField cfield = new TextField("C's scored", 10);
        Button submit = new Button("Submit");
        Button clear = new Button("Clear");
        
        public void reset(){
                showres = false;
                afield.setText("0");
                bfield.setText("0");
                cfield.setText("0");
                aval = 0;
                bval = 0;
                cval = 0;
                papass = false;
                sapass = false;
                capass = false;
                hapass = false;
                eapass = false;
                repaint();
        }

        public void calculate(){
                 if ((cval + bval + aval) >= 6){
                        papass = true;
                 }else {papass = false;
                }if ((aval + bval + cval) >= 12){
                        sapass = true;
                 }else {sapass = false;
                }if ((aval + bval) >= 8 && cval >= (5 - ((aval + bval) - 8))){
                        capass = true;
                 }else {capass = false;
                }if (aval >= 6 && ((aval + bval) - 6) >= 6 && (aval + bval + cval) == 14){
                        hapass = true;
                 }else {hapass = false;
                }if ((aval + bval) == 14 && aval >= 12 && ((aval - 12)+ bval) >= 2){
                        eapass = true;
                 }else {eapass = false;
                }
                repaint();
        
                }
                
        public void init(){
                add(afield);
                add(bfield);
                add(cfield);
                add(submit);
                add(clear);
                afield.addActionListener(this);
                bfield.addActionListener(this);
                cfield.addActionListener(this);
                submit.addActionListener(this);
                clear.addActionListener(this);
        }
        

        public void paint(Graphics g){
                if (showres == true){
                        if(eapass == true){
                                g.drawString("EA Score", 50, 50);
                        } else if (hapass == true) {
                                g.drawString("HA Score", 50, 50);
                        } else if (capass == true){
                                g.drawString("CA Score", 50, 50);
                        } else if (sapass == true){
                                g.drawString("SA Score", 50, 50);
                        } else if (papass == true){
                                g.drawString("PA Score", 50, 50);
                        } else {
                                g.drawString("Failed", 50, 50);
                        }
                }
        }
        public void actionPerformed(ActionEvent e) {
                if(e.getSource() == clear){
                        reset();
                } else {
                showres = true;
                aval = Integer.parseInt(afield.getText());
                bval = Integer.parseInt(bfield.getText());
                cval = Integer.parseInt(cfield.getText());
                calculate();
                }
        }
}//Endcode     